/**
 * pharma-business - 27 févr. 2011
 * guillaume
 */
package org.bspv.pharma.business.rules.order;

import org.bspv.pharma.business.rules.AbstractLeafSpecification;
import org.bspv.pharma.model.OrderDetail;
import org.bspv.pharma.tools.annotations.specification.RG;

/**
 * Règle de gestion vérifiant le respect des quotas pour un détail de commande.
 * @author guillaume
 *
 */
@RG(id="RG_ORDER_DETAIL_QUOTA_001")
public class OrderDetailRespectQuotaRule extends AbstractLeafSpecification<OrderDetail> {

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean isSatisfiedBy(OrderDetail orderDetail) {
        boolean res = orderDetail.getTypeOfSupply().getQuota() == -1;
        res |= orderDetail.getQuantity() <= orderDetail.getTypeOfSupply().getQuota();
        return res;
    }

}
